fix: defer OIDC token acquisition until after Nix evaluation#276
fix: defer OIDC token acquisition until after Nix evaluation#276flexiondotorg wants to merge 1 commit intoDeterminateSystems:mainfrom
Conversation
For large flakes, Nix evaluation (nix flake show --all-systems + output path enumeration) can take 8+ minutes, but GitHub Actions OIDC tokens expire after ~5 minutes. Previously, the token was obtained in PushContext::from_cli_and_env() before evaluation began, causing 401 Unauthorized errors when the token was finally used for API calls. Move token acquisition to just before FlakeHubClient::new() in execute(), after all Nix evaluation completes. Introduce a TokenContext enum that captures environment-specific data needed for each auth method (GitHub, GitLab, Generic, LocalGitHub) without immediately fetching the token. The new acquire_auth_token() method on PushContext handles deferred retrieval. Fixes DeterminateSystems#275
📝 WalkthroughWalkthroughMoved OIDC token acquisition from early PushContext construction to immediately after flake evaluation completes. Introduced a TokenContext enum that defers token retrieval by environment type (GitHub, GitLab, Generic, LocalGitHub), then acquires fresh tokens via a new async method just before FlakeHubClient initialization to prevent token expiry during long evaluations. Changes
Sequence DiagramsequenceDiagram
participant Main as Main (execute)
participant PushCtx as PushContext
participant TokenMgr as Token Acquisition
participant FlakeEval as Flake Evaluation
participant Client as FlakeHubClient
participant API as FlakeHub API
Main->>PushCtx: from_cli_and_env()<br/>(stores TokenContext)
Main->>FlakeEval: Run nix evaluation<br/>(can take 8+ minutes)
FlakeEval-->>Main: Evaluation complete
Main->>TokenMgr: acquire_auth_token()
alt GitHub Actions
TokenMgr->>TokenMgr: get_actions_id_bearer_token()
else GitLab Runner
TokenMgr->>TokenMgr: get_runner_bearer_token()
else Generic
TokenMgr->>TokenMgr: Read FLAKEHUB_PUSH_OIDC_TOKEN env
else LocalGitHub
TokenMgr->>TokenMgr: Generate fake token
TokenMgr->>TokenMgr: Reset to Generic
end
TokenMgr-->>Main: (fresh_token, ctx)
Main->>Client: FlakeHubClient::new(fresh_token)
Client->>API: /token/status (with fresh token)
API-->>Client: 200 OK
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
For large flakes, Nix evaluation (nix flake show --all-systems + output path enumeration) can take 8+ minutes, but GitHub Actions OIDC tokens expire after ~5 minutes. Previously, the token was obtained in PushContext::from_cli_and_env() before evaluation began, causing 401 Unauthorized errors when the token was finally used for API calls.
Move token acquisition to just before FlakeHubClient::new() in execute(), after all Nix evaluation completes. Introduce a TokenContext enum that captures environment-specific data needed for each auth method (GitHub, GitLab, Generic, LocalGitHub) without immediately fetching the token. The new acquire_auth_token() method on PushContext handles deferred retrieval.
Fixes #275
Summary by CodeRabbit
New Features